/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.*;

/**
 * @author Kieu Anh
 */
public class Exit extends Canvas implements CommandListener{

    private Display display;
    private MidletDuaXe midlet;
    private Command cmYes,cmNo;

    public Exit (MidletDuaXe midlet,Display display){

        //this.display = Display.getDisplay(midlet);
        this.display = display;
        this.midlet = midlet;
        cmYes = new Command("Yes", Command.OK, 0);
        cmNo =new Command("No", Command.EXIT, 1);
        this.addCommand(cmNo);
        this.addCommand(cmYes);
        setCommandListener(this);


    }

    protected void paint(Graphics g) {
        g.setColor(200,50, 50);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(255,255,255);
        g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_LARGE));
        String s1 ="Bạn có muốn thoát";
        String s2 ="khỏi chương trình không?";
        g.drawString(s1,getWidth()/2-s1.length()*7/2,getHeight()/2,g.TOP|g.LEFT);
        g.drawString(s2,getWidth()/2-s2.length()*7/2,getHeight()/2+15,g.TOP|g.LEFT);
    }



    
    

    public void commandAction(Command c, Displayable d) {
        //repaint();
        if (c==cmNo) {
            midlet.showMenuGame();
        }
        else if(c==cmYes) {
         midlet.destroyApp(true);
       }
    }
}
